@extends('admin.main')

@section('body')
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>店铺列表</h2>
    </div>
    <div class="cf">
        <div class="fl">
            <a class="btn" href="{{urlAdmin('shop','getAdd')}}">新 增</a>
            <button class="btn ajax-post" url="{{urlAdmin('shop','anySetStatus',['status'=>1])}}"
                    target-form="ids">启 用
            </button>
            <button class="btn ajax-post" url="{{urlAdmin('shop','anySetStatus',['status'=>-1])}}"
                    target-form="ids">禁 用
            </button>
            {{--<button class="btn ajax-post confirm" url="{{urlAdmin('shop','anyChangeStatus',['method'=>'delete'])}}"--}}
            {{--target-form="ids">删 除--}}
            {{--</button>--}}
        </div>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" name="keyword" class="search-input" value="{{request('keyword')}}"
                       placeholder="请输入店铺名称">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlAdmin('shop','getIndex')}}"><i
                            class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
                {{--<th class="">ID</th>--}}
                <th class="">店铺名称</th>
                <th class="">账号</th>
                <th class="">状态</th>
                <th class="">店长姓名</th>
                <th class="">商品数量</th>
                <th class="">水票销量 (桶)</th>
                {{--<th class="">店内水桶</th>--}}
                <th class="">押金总 (元)</th>
                <th class="">续费日期</th>
                <th class="">截止日期</th>
                <th class="">操作</th>
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        <td><input class="ids" type="checkbox" name="ids[]" value="{{$v['id']}}"/></td>
                        {{--<td>{{$v['id']}}</td>--}}
                        <td>
                            {{$v['shop_name']}}
                            @if($v['status'] == 2)
                                <span style="color: red"> (已到期)</span>
                            @elseif($v['end_time'] - (strtotime(date('Y-m-d')) + 3600*24*7)  < 0)
                                <span style="color: orange"> (即将到期)</span>
                            @endif
                        </td>
                        <td>{{$v['username']}}</td>
                        <td style="color: @if($v['status'] == 1) blue @elseif($v['status'] == 2) orange @else red @endif">{{$v['status_text']}}</td>
                        <td>{{$v['boss_name']}}</td>
                        <td>{{$v['total_goods_num']}}</td>
                        <td>{{$v['total_water_bill_num']}}</td>
                        {{--<td>{{$v['total_bucket_num']-$v['total_back_bucket_num']}}</td>--}}
                        <td>{{$v['deposit']}}</td>
                        <td><span>{{$v['start_time'] ? date('Y-m-d',$v['start_time']) : '--'}}</span></td>
                        <td><span style="color: red">{{$v['end_time'] ? date('Y-m-d',$v['end_time']) : '--'}}</span>
                        </td>
                        <td>
                            <a href="javascript:;" onclick="showInfo({{$v['id']}})">详情</a>
                            <a title="轮播图"
                               href="{{urlAdmin('shop','getSliders',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">轮播图</a>
                            <a title="设置"
                               href="{{urlAdmin('shop','getSetting',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">设置</a>
                            <a title="广播"
                               href="{{urlAdmin('shop','getNotice',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">广播</a>
                            <a title="编辑"
                               href="{{urlAdmin('shop','getEdit',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">编辑</a>
                            <a title="账号"
                               href="{{urlAdmin('shop','getAccount',['shop_id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">账号</a>
                            @if($v['status'] == 1)
                                <a href="{{urlAdmin('shop','anySetStatus',['status'=>-1,'ids'=>$v['id']])}}"
                                   class="ajax-get" style="color:red">禁用</a>
                            @elseif($v['end_time'] - (strtotime(date('Y-m-d')) + 3600*24*7)  < 0 || $v['status'] == 2)
                                <a href="{{urlAdmin('shop','getCharge',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}"
                                   style="color: orange">续费</a>
                            @elseif($v['end_time'] - (strtotime(date('Y-m-d')) + 3600*24*7)  > 0 && $v['status'] == -1)
                                <a href="{{urlAdmin('shop','anySetStatus',['status'=>1,'ids'=>$v['id']])}}"
                                   class="ajax-get" style="color:blue">启用</a>
                            @endif
                        </td>
                    </tr>
                @endforeach
            @else
                <td colspan="12" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num" href="{{urlAdmin('shop','getIndex',['page'=>$v])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                @endif
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')

    <script type="text/javascript">
        function showInfo(id) {
//iframe层
            layer.open({
                type: 2,
                title: '店铺详情',
                area: ['450px', '360px'],
                fixed: false, //不固定
                content: '{{urlAdmin('shop','getInfo')}}?id=' + id
            });
        }
        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });
        //回车搜索
        $(".search-input").keyup(function (e) {
            if (e.keyCode === 13) {
                $("#search").click();
                return false;
            }
        });
    </script>
@endsection
